# 连接数据库
import pymysql, json

# # 连接数据库
# conn = pymysql.Connect(
#     host='47.94.130.233',
#     port=3306,
#     user='root',
#     passwd='123456',
#     db='training',
#     charset='utf8',
# )
# # 获取游标
# my_cursor = conn.cursor()
# # 准备SQL
# sql = 'insert into emp (mobile,password,nickname) values (%s,%s,%s)'
# # 准备插入的数据
# data = [
#     ('15311484568', '123456', '李昊哲'),
#     ('18515697037', '123456', 'phoenix')
# ]
#
# try:
#     # 批量插入数据
#     my_cursor.executemany(sql, data)
#     # 手动提交事务
#     conn.commit()
#     print('提交了', my_cursor.rowcount, '条数据')
# except Exception as e:
#     print(e)
#     # 事务回滚
#     conn.rollback()
# finally:
#     # 关闭连接
#     conn.close()

data = []

with open(file='area_data.json', mode='r', encoding='utf-8') as f:
    area = json.load(f)
    province_area = area.get('data')
    # print(province_area)
    for region_province in province_area:
        province_code = region_province.get('regionCode')
        cities = region_province.get('cities')
    #     data.append((province_code,region_province.get('regionName'),))
        print(region_province)
        # print(cities)
        # cicty_code = cities.get('regionCode')
        # data.append((cicty_code, cities.get('regionName'),))
        # for counties in cities:
        #     print(counties)
            # print(f'{parent_code} >>> {region_name}')


    # print(data)